import request from '@/utils/request'

// 获取房源位置信息
export const getRoomLocationApi = (roomId) => {
  return request({
    url: `/api/rooms/${roomId}/location`,
    method: 'get'
  })
}

// 批量获取房源位置信息
export const getBatchRoomLocationsApi = (roomIds) => {
  return request({
    url: '/api/rooms/locations',
    method: 'post',
    data: { roomIds }
  })
}

// 根据地址获取坐标
export const getCoordinatesByAddressApi = (address) => {
  return request({
    url: '/api/location/geocode',
    method: 'post',
    data: { address }
  })
}

// 根据坐标获取地址
export const getAddressByCoordinatesApi = (lat, lng) => {
  return request({
    url: '/api/location/reverse-geocode',
    method: 'post',
    data: { lat, lng }
  })
}

// 搜索附近房源
export const searchNearbyRoomsApi = (lat, lng, radius = 5000, params = {}) => {
  return request({
    url: '/api/rooms/nearby',
    method: 'post',
    data: {
      lat,
      lng,
      radius,
      ...params
    }
  })
}

// 获取城市边界
export const getCityBoundsApi = (cityName) => {
  return request({
    url: '/api/location/city-bounds',
    method: 'post',
    data: { cityName }
  })
}

// 计算两点间距离
export const calculateDistanceApi = (fromLat, fromLng, toLat, toLng) => {
  return request({
    url: '/api/location/distance',
    method: 'post',
    data: {
      from: { lat: fromLat, lng: fromLng },
      to: { lat: toLat, lng: toLng }
    }
  })
}
